// import 'package:/model/home_model.dart';
import 'package:flutter_trip_demo/model/search_model.dart';
import 'dart:async';
import 'dart:convert';
import 'package:http/http.dart' as http;

import '../model/home_model.dart';

/*
*1.import 'package:http/http.dart' as http;  as 害怕重名和一个冲突  是一个别名
*
* */

class SearchDio {
  static Future<SearchModel> fetch(String url,String e) async {
    var urls = Uri.parse(url);

    final response = await http.get(urls);

    if (response.statusCode == 200) {
      //解决中文乱码的问题
      Utf8Decoder utf8decoder = Utf8Decoder();
      var result = json.decode(utf8decoder.convert(response.bodyBytes));
      SearchModel model =  SearchModel.fromJson(result);
      model.keyword = e;
      return model;
    } else {
      throw Exception('data fail');
    }
  }
}
